package net.flintx.array;

public class BestTimetoBuyandSellStock2 {
    public int maxProfit(int[] prices) {
        int maxPrice = 0;
        for (int i = 1; i < prices.length; i++) {
            maxPrice += Math.max(0, prices[i] - prices[i-1]);
        }
        return maxPrice;
    }

    public static void main(String[] args) {
        int[] prices = {7, 1, 5, 3, 6, 4};
        System.out.println(new BestTimetoBuyandSellStock2().maxProfit(prices));
    }
}
